<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>组件环境添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script type="text/javascript"
            src="../lib/vue/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <script type="text/javascript" src="../js/global.js"></script>
    <script type="text/javascript" src="../js/store.js"></script>
    <script type="text/javascript" src="../js/cookies.js"></script>
    <script src="../lib/vue/vue.min.js"></script>
    <script src="../lib/vue/axios.min.js"></script>
</head>

<body>
<div class="x-body layui-anim layui-anim-up">
    <form class="layui-form">
        <div class="layui-form-item" hidden>
            <div class="layui-input-inline">
                <input type="text" id="L_userId" name="requestUserId" required=""
                       lay-verify=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" hidden>
            <div class="layui-input-inline">
                <input type="text" id="L_companyId" name="companyId" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属公司</label>
            <div class="layui-inline" style="width: 300px;">
                <input type="text" id="L_companyName" name="companyName" autocomplete="off" class="layui-input"
                       readonly>
            </div>
        </div>
        <div class="layui-form-item" hidden>
            <div class="layui-input-inline">
                <input type="text" id="L_sysId" name="sysId" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属系统</label>
            <div class="layui-inline" style="width: 300px;">
                <input type="text" id="L_sysName" name="sysName" autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属系统</label>
            <div class="layui-inline" style="width: 300px;">
                <input type="text" id="L_userName" name="requestUserName" autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_componentName" class="layui-form-label">
                <span class="x-red">*</span>申请组件
            </label>
            <div class="layui-input-inline">
                <select id="L_componentName" name="componentId" lay-verify="componentId">

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                新增
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery
        var form = layui.form
            , layer = layui.layer
        $('#L_companyName').val(getCookie('companyName'))
        $('#L_companyId').val(parseInt(getCookie('companyId')))
        $("#L_sysName").val(getCookie('sysName'))
        $("#L_sysId").val(parseInt(getCookie('sysId')))
        $("#L_userId").val(parseInt(getCookie('userId')))
        $("#L_userName").val(getCookie('username'))
        form.render();
        /*//自定义验证规则
        form.verify({
            envName: function (value) {
                if (value.length < 1) {
                    return '环境名称不可为空'
                }
            }
        })*/
        //获取选中的数据 进行格式转换，并加载到form表单中
        //获取组件下拉表
        $.get(_hostUrl + '/cmsComponents/'+parseInt(getCookie('userId')), function (res) {
            if (res.responseCode != 200) {
                layer.msg(res.responseMsg, {icon: 2, time: 1500});
                return;
            } else {
                let componentArray = res.data;
                for (var i = 0; i < componentArray.length; i++) {
                    $('#L_componentName').append(new Option(componentArray[i].componentName, componentArray[i].id))// 下拉菜单里添加元素
                }
                $('#L_componentName').val(parseInt(getUrlKey('id')));
                form.render();
            }
        })
        //监听提交
        form.on('submit(add)', function (data) {
            $.post(_hostUrl + "/cmsApplicationForm", data.field, function (res) {
                if (res.responseCode == 201) {
                    layer.msg('申请发送成功', {
                        icon: 1,
                        time: 2000
                    }, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                        var table = parent.window.layui.table;
                        table.reload('requestionList');
                    });
                } else {
                    layer.msg(res.responseMsg, {icon: 2, time: 1500})
                }
            }, 'json')
            return false
        })
    })
</script>
</body>

</html>